/**
 * @Author: Ray丶X
 * @Date: 2020/3/24
 */

// --------------------------------------
// 读取流
// var fs = require('fs');
// var data = '';
//
// var readStream = fs.createReadStream('input.txt');
//
// readStream.setEncoding('UTF-8');
//
// readStream.on('data', function (chunck) {
//   data += chunck;
// });
//
// readStream.on('end', function () {
//   console.log(data);
// });
//
// readStream.on('error', function (err) {
//   console.log(err.stack);
// });

// console.log('执行完毕');
// --------------------------------------

// --------------------------------------
// 写入流
// var writefs = require('fs');
// var writeData = '写入的流';
//
// var writeStream = writefs.createWriteStream('output.txt');
//
// writeStream.write(writeData, 'UTF-8');
//
// writeStream.end();
//
// writeStream.on('finish', function () {
//   console.log('写入完成');
// });
//
// writeStream.on('error', function (err) {
//   console.log(err.stack);
// });
//
// console.log('程序完成');
// --------------------------------------

// --------------------------------------
// 管道流pipe

var fs = require('fs');

var readStream = fs.createReadStream('input.txt');
var outputStream = fs.createWriteStream('output2.txt');

readStream.pipe(outputStream);

console.log('程序完成');
// --------------------------------------
